package com.example.educationai.service.impl;

import com.example.educationai.entity.ClassEntity;
import com.example.educationai.entity.SimpleUser;
import com.example.educationai.repository.ClassRepository;
import com.example.educationai.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class ClassServiceImpl implements ClassService {
    
    @Autowired
    private ClassRepository classRepository;
    
    @Override
    public List<ClassEntity> getTeacherClasses(SimpleUser teacher) {
        return classRepository.findByTeacher(teacher);
    }
    
    @Override
    public List<ClassEntity> findByTeacherId(Long teacherId) {
        return classRepository.findByTeacherId(teacherId);
    }
    
    @Override
    public ClassEntity save(ClassEntity classEntity) {
        return classRepository.save(classEntity);
    }
    
    @Override
    public void deleteById(Long id) {
        classRepository.deleteById(id);
    }
    
    @Override
    public ClassEntity getClass(Long id) {
        return classRepository.findById(id)
                .orElseThrow(() -> new RuntimeException("班级不存在"));
    }
    
    @Override
    public ClassEntity updateClass(ClassEntity classEntity) {
        return classRepository.save(classEntity);
    }
    
    @Override
    public boolean existsByClassNameAndGrade(String className, String grade) {
        return classRepository.existsByClassNameAndGrade(className, grade);
    }
} 